home *** CD-ROM | disk | FTP | other *** search
/ Teach Your Children: Road Construction Ahead / Teach Your Children: Road Construction Ahead.iso / mac / Road Construction Ahead / Road Construction Ahead / 00019_HardHat Parent.ls < prev    next >
Encoding:
Text File  |  1996-07-17  |  6.2 KB  |  212 lines

  1. property howManyHats, hardHatBmap, hatsInRow, horizDist, vertDist, trailsSprite, originX, originY, numberSlotLocH, numberSlotLocV, firstNumeral, firstNumeralChan, displayDigits, counterNumber, animCounter, minLoops, bgChannel, hatLoopLength, hLoc, vLoc
  2. global gActorList, gHiddenActorList, gRollAnimButton, gMenuObject, gAwardsObject, gCDpath
  3.  
  4. on birth me
  5.   set howManyHats to 0
  6.   set hardHatBmap to the number of cast "OneHardHat"
  7.   set hatsInRow to 10
  8.   set horizDist to 59
  9.   set vertDist to 35
  10.   set trailsSprite to 8
  11.   set originX to 55
  12.   set originY to 28
  13.   set numberSlotLocH to 77
  14.   set numberSlotLocV to 433
  15.   set firstNumeralChan to 4
  16.   set bgChannel to 2
  17.   set displayDigits to 3
  18.   set minLoops to 2
  19.   set hatLoopLength to 4
  20.   set firstNumeral to the number of cast "ZeroBitmap"
  21.   return me
  22. end
  23.  
  24. on setup me
  25.   drawHardHats(me)
  26.   add(gActorList, birth(script "Rollover Anim Button Class", "goMenu( gHardHatObject, me )", 11, 11, 5, "RCA-07VO01", "RCA-07RO01"))
  27.   add(gActorList, birth(script "Rollover Anim Button Class", "help( gHardHatObject, me )", 12, 12, 11, EMPTY, "RCA-05RO02"))
  28.   puppetAll()
  29.   if howManyHats > 0 then
  30.     giveAward(gAwardsObject, "HardHat")
  31.   end if
  32. end
  33.  
  34. on update me
  35.   if counterNumber < howManyHats then
  36.     if animCounter < hatLoopLength then
  37.       set animCounter to animCounter + 1
  38.       set the castNum of sprite 48 to hardHatBmap + animCounter
  39.     else
  40.       finishNumberSound(me)
  41.       resetSprites(me)
  42.       set counterNumber to counterNumber + 1
  43.       set displayString to padString(me, counterNumber, displayDigits)
  44.       refreshCounter(me, displayString)
  45.       set row to ((counterNumber - 1) / 10) + 1
  46.       set column to counterNumber - (10 * (row - 1))
  47.       set hLoc to originX + ((column - 1) * horizDist)
  48.       set vLoc to originY + ((row - 1) * vertDist)
  49.       set animCounter to 1
  50.       set the castNum of sprite 48 to hardHatBmap + animCounter
  51.       set the locH of sprite 48 to hLoc
  52.       set the locV of sprite 48 to vLoc
  53.       sound playFile 1, gCDpath & "SOUND:NUMBERS:" & string(counterNumber) & ".AIF"
  54.     end if
  55.   else
  56.     if animCounter < hatLoopLength then
  57.       set animCounter to animCounter + 1
  58.       set the castNum of sprite 48 to hardHatBmap + animCounter
  59.     else
  60.       finishNumberSound(me)
  61.       set gActorList to []
  62.       showAllActors()
  63.       resetSprites(me)
  64.       set the mouseDownScript to EMPTY
  65.       puppetSound(0)
  66.     end if
  67.   end if
  68.   puppetTempo(15)
  69. end
  70.  
  71. on finishNumberSound me
  72.   if soundBusy(1) then
  73.     set the castNum of sprite 48 to hardHatBmap
  74.     go(the frame)
  75.     abort()
  76.   end if
  77. end
  78.  
  79. on countOff me
  80.   if (getPos(gActorList, me) = 0) and (howManyHats > 0) then
  81.     eraseAllHats(me)
  82.     set counterNumber to 1
  83.     set displayString to padString(me, counterNumber, displayDigits)
  84.     refreshCounter(me, displayString)
  85.     set animCounter to 1
  86.     set the locH of sprite 48 to originX
  87.     set the locV of sprite 48 to originY
  88.     set the castNum of sprite 48 to hardHatBmap + animCounter
  89.     add(gActorList, me)
  90.     hideOtherActors(me)
  91.     sound playFile 1, gCDpath & "SOUND:NUMBERS:" & string(counterNumber) & ".AIF"
  92.     set the mouseDownScript to "interruptCounting"
  93.   end if
  94. end
  95.  
  96. on interruptCountOff me
  97.   removeSprite(48)
  98.   eraseAllHats(me)
  99.   set gActorList to []
  100.   set displayString to padString(me, howManyHats, displayDigits)
  101.   refreshCounter(me, displayString)
  102.   drawHardHats(me)
  103.   set the mouseDownScript to EMPTY
  104.   showAllActors()
  105.   puppetSound(0)
  106. end
  107.  
  108. on addHat me, soundName
  109.   if howManyHats < 100 then
  110.     set howManyHats to howManyHats + 1
  111.   end if
  112.   puppetSound(soundName)
  113.   removeSprite(the clickOn)
  114.   updateStage()
  115.   puppetSprite(the clickOn, 0)
  116.   repeat while soundBusy(1)
  117.   end repeat
  118.   puppetSound(0)
  119. end
  120.  
  121. on eraseAllHats me
  122.   set the castNum of sprite trailsSprite to the castNum of sprite bgChannel
  123.   set the locH of sprite trailsSprite to the locH of sprite bgChannel
  124.   set the locV of sprite trailsSprite to the locV of sprite bgChannel
  125.   updateStage()
  126.   removeSprite(trailsSprite)
  127. end
  128.  
  129. on predraw me
  130.   set displayString to padString(me, howManyHats, displayDigits)
  131.   refreshCounter(me, displayString)
  132. end
  133.  
  134. on refreshCounter me, displayString
  135.   repeat with slot = 1 to displayDigits
  136.     set channel to firstNumeralChan + slot - 1
  137.     set bitmapOffset to value(char slot of displayString)
  138.     set the castNum of sprite channel to firstNumeral + bitmapOffset
  139.     set the locH of sprite channel to numberSlotLocH + ((slot - 1) * 32)
  140.     set the locV of sprite channel to numberSlotLocV
  141.     puppetSprite(channel, 1)
  142.   end repeat
  143. end
  144.  
  145. on padString me, someNumber, totalDigits
  146.   set stringNumber to string(someNumber)
  147.   set stringLength to length(stringNumber)
  148.   set paddedString to EMPTY
  149.   repeat with x = 1 to totalDigits - stringLength
  150.     set paddedString to paddedString & "0"
  151.   end repeat
  152.   repeat with x = 1 to stringLength
  153.     set paddedString to paddedString & char x of stringNumber
  154.   end repeat
  155.   return paddedString
  156. end
  157.  
  158. on drawHardHats me
  159.   set the castNum of sprite trailsSprite to hardHatBmap
  160.   set columnCounter to 0
  161.   set rowCounter to 1
  162.   repeat with x = 1 to howManyHats
  163.     set columnCounter to columnCounter + 1
  164.     if columnCounter > hatsInRow then
  165.       set columnCounter to 1
  166.       set rowCounter to rowCounter + 1
  167.     end if
  168.     set the locH of sprite trailsSprite to originX + ((columnCounter - 1) * horizDist)
  169.     set the locV of sprite trailsSprite to originY + ((rowCounter - 1) * vertDist)
  170.     updateStage()
  171.   end repeat
  172.   removeSprite(trailsSprite)
  173.   updateStage()
  174. end
  175.  
  176. on resetSprites me
  177.   set the castNum of sprite 48 to hardHatBmap
  178.   set the locH of sprite trailsSprite to the locH of sprite 48
  179.   set the locV of sprite trailsSprite to the locV of sprite 48
  180.   set the castNum of sprite trailsSprite to hardHatBmap
  181.   updateStage()
  182.   removeSprite(48)
  183.   updateStage()
  184.   removeSprite(trailsSprite)
  185.   updateStage()
  186. end
  187.  
  188. on saveHardHats me
  189.   set hardHatData to string(howManyHats) & ","
  190.   return hardHatData
  191. end
  192.  
  193. on loadHardHats me, index
  194.   set howManyHats to value(item index of the dataString of gMenuObject)
  195.   return index + 1
  196. end
  197.  
  198. on goMenu me, buttonObject
  199.   clearAllActors()
  200.   unpuppetAll()
  201.   makeButtonJump(buttonObject)
  202.   puppetPalette("HardHatPal")
  203.   go("Grass")
  204.   puppetPalette("MainPal")
  205.   unLoadCast()
  206.   goLocationMap()
  207. end
  208.  
  209. on help me, buttonObject
  210.   birth(script "Help Parent", buttonObject, #HardHat)
  211. end
  212.